<template>
  <div class="contestant-dashboard">
    <el-container>
      <el-aside width="220px">
        <div class="sidebar">
          <div class="logo-container">
            <h2>参赛者中心</h2>
          </div>
          <el-menu
            :default-active="activeMenu"
            class="el-menu-vertical"
            background-color="#304156"
            text-color="#bfcbd9"
            active-text-color="#409EFF"
            router>
            <el-menu-item index="/contestant/works">
              <i class="el-icon-picture-outline"></i>
              <span>我的参赛作品</span>
            </el-menu-item>
            <el-menu-item index="/contestant/profile">
              <i class="el-icon-user"></i>
              <span>个人信息</span>
            </el-menu-item>
            <el-menu-item index="/" @click="goToHome">
              <i class="el-icon-back"></i>
              <span>返回首页</span>
            </el-menu-item>
          </el-menu>
        </div>
      </el-aside>
      
      <el-container>
        <el-header>
          <div class="header-container">
            <div class="breadcrumb">
              <el-breadcrumb separator="/">
                <el-breadcrumb-item :to="{ path: '/contestant' }">参赛者中心</el-breadcrumb-item>
                <el-breadcrumb-item v-if="$route.path === '/contestant/works'">我的参赛作品</el-breadcrumb-item>
                <el-breadcrumb-item v-else-if="$route.path === '/contestant/profile'">个人信息</el-breadcrumb-item>
              </el-breadcrumb>
            </div>
            <div class="user-info">
              <el-dropdown trigger="click" @command="handleCommand">
                <span class="dropdown-link">
                  {{ nickname || username }}
                  <i class="el-icon-arrow-down el-icon--right"></i>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item command="logout">退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </div>
          </div>
        </el-header>
        
        <el-main>
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { mapGetters, mapActions } from 'vuex'

export default {
  name: 'ContestantDashboard',
  computed: {
    ...mapGetters(['nickname', 'username']),
    activeMenu() {
      return this.$route.path
    }
  },
  methods: {
    ...mapActions(['logout']),
    handleCommand(command) {
      if (command === 'logout') {
        this.logout()
        this.$message.success('退出登录成功')
        this.$router.push('/')
      }
    },
    goToHome() {
      this.$router.push('/')
    }
  }
}
</script>

<style scoped>
.contestant-dashboard {
  min-height: 100vh;
  display: flex;
}

.el-container {
  height: 100vh;
  width: 100%;
}

.el-aside {
  background-color: #304156;
  color: #bfcbd9;
  height: 100%;
  overflow-x: hidden;
}

.sidebar {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.logo-container {
  height: 60px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid #1f2d3d;
}

.logo-container h2 {
  color: #409EFF;
  margin: 0;
  font-size: 18px;
}

.el-menu {
  border-right: none;
  flex: 1;
}

.el-header {
  background-color: #fff;
  border-bottom: 1px solid #e6e6e6;
  height: 60px !important;
  line-height: 60px;
  padding: 0 20px;
}

.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
}

.user-info {
  display: flex;
  align-items: center;
}

.dropdown-link {
  cursor: pointer;
  color: #409EFF;
  display: flex;
  align-items: center;
}

.el-main {
  background-color: #f0f2f5;
  padding: 20px;
}

@media (max-width: 768px) {
  .el-aside {
    width: 64px !important;
  }
  
  .el-menu--vertical {
    width: 64px;
  }
  
  .logo-container h2 {
    display: none;
  }
}
</style> 